package com.gc.common.util;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import java.util.List;

/**
 * Created by 瑱彬 on 2015/4/2.
 */
public class ReturnJsonUtil {

    public static Integer SUCCESS_CODE = 1;
    public static Integer ERROR_CODE = -1;

    public static JSONObject successMsg(String msg) {
        JSONObject result = new JSONObject();
        result.put("ret", SUCCESS_CODE);
        result.put("msg", msg);
        return result;
    }

    public static JSONObject successCount(Integer count) {
        JSONObject result = new JSONObject();
        result.put("ret", SUCCESS_CODE);
        result.put("count", count);
        return result;
    }

    public static JSONObject successRows(List list) {
        JSONObject result = new JSONObject();
        result.put("ret", SUCCESS_CODE);
        JSONArray rows = new JSONArray();
        rows.addAll(list);
        result.put("rows", rows);
        return result;
    }

    public static JSONObject errorMsg(String msg) {
        JSONObject result = new JSONObject();
        result.put("ret", ERROR_CODE);
        result.put("msg", msg);
        return result;
    }
}
